//
//  LZMeViewController.m
//  LZBS
//
//  Created by 郝庆 on 16/6/8.
//  Copyright © 2016年 haoqing. All rights reserved.
//

#import "LZMeViewController.h"
#import "LZSettingViewController.h"
#import "LZLoginRegisterViewController.h"
#import "LZMeCell.h"
#import "LZMeFooterView.h"

@interface LZMeViewController ()

@end

@implementation LZMeViewController

/**
 *  设置TableView的样式为分组样式
 */
- (instancetype)init
{
    return [self initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置导航控制器的相关属性
    [self setUpNav];
    
    // 设置TableView的相关属性
    [self setUpTableView];
    
}

#pragma mark - 设置TableView的相关属性
- (void)setUpTableView
{
    self.tableView.backgroundColor = LZCommonBgColor;
    self.tableView.contentInset = UIEdgeInsetsMake(LZMargin - 35, 0, 0,0);
    self.tableView.sectionHeaderHeight = 0;
    self.tableView.sectionFooterHeight = LZMargin;
    self.tableView.tableFooterView = [[LZMeFooterView alloc] init];
    
}

#pragma mark - 设置导航控制器的相关属性
- (void)setUpNav
{
    // 中间标题
    self.navigationItem.title = @"我的";
    
    // 右边
    UIBarButtonItem *settingItem = [UIBarButtonItem lz_itemWithImage:@"mine-setting-icon" highImage:@"mine-setting-icon-click" target:self action:@selector(settingBtnClick)];
    UIBarButtonItem *moonItem = [UIBarButtonItem lz_itemWithImage:@"mine-moon-icon" highImage:@"mine-moon-icon-click" target:self action:@selector(moonBtnClick)];
    
    self.navigationItem.rightBarButtonItems = @[settingItem,moonItem];
}

- (void)settingBtnClick
{
    LZSettingViewController *settingVc = [[LZSettingViewController alloc] init];
    
    [self.navigationController pushViewController:settingVc animated:YES];
    
}

- (void)moonBtnClick
{
    LZLog(@"进入夜间模式");
}

#pragma mark - 数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 1.确定重用标示
    static NSString *ID = @"cell";
    // 2.从缓存池中取
    LZMeCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    // 3.如果空就手动创建
    if (cell == nil) {
        cell = [[LZMeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    // 4.设置cell的内容
    if (indexPath.section == 0) {
        cell.textLabel.text = @"登录/注册";
        cell.imageView.image = [UIImage imageNamed:@"setup-head-default"];
    } else {
        cell.textLabel.text = @"离线下载";
        cell.imageView.image = nil;
    }
    
    return cell;
}

#pragma mark - 代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 点击 登录/注册
    if (indexPath.section == 0) {
        LZLoginRegisterViewController *loginVc = [[LZLoginRegisterViewController alloc] init];
        [self presentViewController:loginVc animated:YES completion:nil];
    }
}

@end
